package data;

import java.util.Arrays;
import java.util.Locale;

/**
 * 
 * A sentence class for searching
 * 
 * @author Stephen
 * 
 */

public class Sentence {

	/** words in the sentence */
	private String[] words;

	/**
	 * Default constructor of a sentence
	 * 
	 * @param sentence
	 *            - the string that this sentence will be about
	 */
	public Sentence(String sentence) {
		sentence = sentence.toLowerCase(Locale.US);
		sentence = sentence.replace("[.!?\\-]", ""); // remove the punctuation;
		words = sentence.split("\\s");
	}

	/**
	 * Returns the word in the sentence
	 * 
	 * @return - the words in the sentence
	 */
	public String[] getWords() {
		return words;
	}

	/**
	 * returns the string representation of the sentence
	 * 
	 * @return string - the string representation
	 */
	@Override
	public String toString() {
		return Arrays.toString(words);
	}

	/**
	 * Counts how many times each word in this sentence appears in the other
	 * 
	 * @param other
	 *            - the sentence to compare to
	 * @return - the amount of word similarities in this sentence and other
	 */
	public int similarWordCount(Sentence other) {
		int count = 0;

		for (int i = 0; i < other.getWords().length; i++) {
			for (int j = 0; j < words.length; j++) {
				if (other.getWords()[i].equals(words[j])) {
					count++;
				}
			}
		}
		return count;
	}

}
